<template>
    <div class="blank-page">

    </div>
</template>

<script>
    /**
     * Created by c.y on 2018/4/3.
     * 空白页
     */
    import systemApi from '../../api/api';
    import store from '../../store/index';
    import statusCodeManage from '../../api/statusCodeManage';

    export default {
        name: 'f-blank-page',
        data(){
            return {

            }
        },
        methods:{
            init:function () {
                let _this = this;

                let _newClientInfo =null;
                _newClientInfo = window.localStorage.getItem('newClientInfo');
                _newClientInfo = JSON.parse(_newClientInfo);
                // 这里区分是 H5 还是 原生环境
                if(_newClientInfo.cn == ''){  // 这里是原生环境
                    let _intId = setInterval(function () {
                        _newClientInfo = window.localStorage.getItem('newClientInfo');
                        _newClientInfo = JSON.parse(_newClientInfo);
                        // console.log(_newClientInfo)
                        if(_newClientInfo.appVersion && _newClientInfo.appVersion.length){
                            _this.getRouterConfig();
                            clearInterval(_intId);
                        }
                    },40)
                }else{  // H5 环境
                    _this.$router.push({ path: '/f-main',query:{cn:_newClientInfo.cn} });
                }

            },
            getRouterConfig:function () {
                let _this = this;
                systemApi.getRouterControlConfig().then(
                    res => {
                        if(res){
                            store.commit('UPDATE_LOADING', {isLoading: false});
                            let router = true;
                            let routerConfig = res.isPublish;
                            //根据配置文件去控制使用 审核业务路由 还是 正常路由
                            let _clientInfo = window.localStorage.getItem ('newClientInfo');
                            _clientInfo = JSON.parse (_clientInfo);
                            let _chanNo = routerConfig[_clientInfo.chanNo];
                            for (let _obj in _chanNo) {
                                if (_chanNo[_obj][_clientInfo.childChan] != undefined) {
                                    const _len = _chanNo[_obj][_clientInfo.childChan].length;
                                    const _appVerisonArr = _chanNo[_obj][_clientInfo.childChan];
                                    for (let i = 0; i < _len; i++) {
                                        if (_appVerisonArr[i] == _clientInfo.appVersion) {
                                            // 进入审核业务路由
                                            router = false;
                                            // window.localStorage.setItem('initRouter','auditRouter');
                                            // _this.$router.addRoutes(auditRouter);
                                            // _this.$router.push({ path: '/f-main' });
                                            _this.$router.push({ path: '/login' });
                                            return false;
                                        }
                                    }
                                }
                            }
                            if(router){
                                // 跳转到 旧C 端
                                // _this.$router.addRoutes(auditRouter);
                                // 进入到这个判断一定是原生环境
                                _this.$router.push({ path: '/f-main'});
                            }
                        }
                    },
                    error => {
                        statusCodeManage.showTipOfStatusCode(error,_this);
                    }
                );
            }
        },
        activated(){
            store.commit('UPDATE_LOADING', {isLoading: true});
            this.init()
        }
    };
</script>


<style lang="less">
</style>
